<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>发布宝贝页面</h1>
<form action="">
    <input type="text" name="title" placeholder="宝贝标题"><br>
    <input type="text" name="content" placeholder="商品描述"><br>
    <input type="file" name="picFile"><br>
    <input type="text" name="sort" placeholder="属于的类型"><br>
    <input type="button" value="发布" @click="send()"><br>
</form>
<!--引入CDN服务器的框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script>
    let v = new Vue({
        el:"form",
        methods:{
            send:function () {
                let data = new FormData(document.querySelector("form"));
                if (data.get("picFile").name==""){
                    alert("请选择上传的图片!");
                    return;
                }
                axios.post("/baobei/insert",data).then(function (response) {
                    if (response.data==1){
                        alert("发布成功!");
                        location.href="/";//回到首页
                    }else{
                        alert("请先登录!");
                        location.href="/login.html";
                    }
                })
            }
        }
    })
</script>
</body>
</html>